<?php

namespace app\common\model\banxi\learn;

use app\common\enums\CourseDeliveryTypeEnum;
use app\common\enums\CourseFullTypeEnum;
use app\common\model\banxi\organization\Organization;
use app\common\model\banxi\student\Student;
use app\common\model\banxi\trainer\Trainer;
use app\common\model\common\BaseModel;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 上课记录
 */
class LearnReading extends BaseModel
{
    use SoftDelete;

    protected $name = 'banxi_learn_reading';

    protected $autoWriteTimestamp = true;

    protected $deleteTime = 'del';

    protected $defaultSoftDelete = 0;

    protected $append = [
        'courseFullTypeCn',
        'courseDeliveryTypeCn'
    ];

    protected $type = [
        'id' => 'string',
        'del' => 'string',
        'skRecordId' => 'string',
        'courseId' => 'string',
        'trainerId' => 'string',
        'createTime' => 'timestamp:Y-m-d H:i:s',
        'updateTime' => 'timestamp:Y-m-d H:i:s',
    ];

    //-----------------------------------------------------------------------------------
    //｜                                   获取器                                       ｜
    //-----------------------------------------------------------------------------------

    public function getCourseFullTypeCnAttr($value, $data)
    {
        $value = $value ?: ($data['courseFullType'] ?? '');
        return (new CourseFullTypeEnum())->getDescription($value) ?? '';
    }

    public function getCourseDeliveryTypeCnAttr($value, $data)
    {
        $value = $value ?: ($data['courseDeliveryType'] ?? '');
        return (new CourseDeliveryTypeEnum())->getDescription($value) ?? '';
    }


    //-----------------------------------------------------------------------------------
    //｜                                   处理方法                                       ｜
    //-----------------------------------------------------------------------------------





    //-----------------------------------------------------------------------------------
    //｜                                   模型关联                                       ｜
    //-----------------------------------------------------------------------------------

    public function studentInfo()
    {
        return $this->hasOne(Student::class, 'id', 'studentId');
    }

    public function trainerInfo()
    {
        return $this->hasOne(Trainer::class, 'id', 'trainerId');
    }

    public function organizationBaseInfo()
    {
        return $this->hasOne(Organization::class, 'id', 'studentOrgId');
    }

}